package com.sskj.trafficcontrol.util.weather;

/**
 * @author : zhao kuo
 * @date : 2019/2/15 12:44
 * @description :
 */

import com.sskj.trafficcontrol.util.XMLUtil;

import java.util.Date;

/**
 *
 * @author Steven
 *
 */
public class Test {
    public static void main(String[] args) {
        ClassRoom classRoom = new ClassRoom();
        classRoom.setId(1);
        classRoom.setName("班级");
        // 创建需要转换的对象
        User user = new User(1, "Steven", "@sun123", new Date(), 1000.0,classRoom);
        System.out.println("---将对象转换成string类型的xml Start---");
        // 将对象转换成string类型的xml
//        String str = XMLUtil.convertToXml(user);
        String str ="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "\n" +
                "<resp>\n" +
                "  <city>杭州</city>\n" +
                "  <updatetime>12:15</updatetime>\n" +
                "  <wendu>6</wendu>\n" +
                "  <fengli><![CDATA[3级]]></fengli>\n" +
                "  <shidu>95%</shidu>\n" +
                "  <fengxiang>北风</fengxiang>\n" +
                "  <sunrise_1>06:41</sunrise_1>\n" +
                "  <sunset_1>17:48</sunset_1>\n" +
                "  <sunrise_2/>\n" +
                "  <sunset_2/>\n" +
                "  <forecast>\n" +
                "    <weather>\n" +
                "      <date>15日星期五</date>\n" +
                "      <high>高温 7℃</high>\n" +
                "      <low>低温 4℃</low>\n" +
                "      <day>\n" +
                "        <type>小雨</type>\n" +
                "        <fengxiang>无持续风向</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </day>\n" +
                "      <night>\n" +
                "        <type>小雨</type>\n" +
                "        <fengxiang>东北风</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </night>\n" +
                "    </weather>\n" +
                "    <weather>\n" +
                "      <date>16日星期六</date>\n" +
                "      <high>高温 4℃</high>\n" +
                "      <low>低温 1℃</low>\n" +
                "      <day>\n" +
                "        <type>小雪</type>\n" +
                "        <fengxiang>西南风</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </day>\n" +
                "      <night>\n" +
                "        <type>阴</type>\n" +
                "        <fengxiang>东北风</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </night>\n" +
                "    </weather>\n" +
                "    <weather>\n" +
                "      <date>17日星期天</date>\n" +
                "      <high>高温 5℃</high>\n" +
                "      <low>低温 2℃</low>\n" +
                "      <day>\n" +
                "        <type>小雨</type>\n" +
                "        <fengxiang>东北风</fengxiang>\n" +
                "        <fengli><![CDATA[3-4级]]></fengli>\n" +
                "      </day>\n" +
                "      <night>\n" +
                "        <type>小雨</type>\n" +
                "        <fengxiang>东北风</fengxiang>\n" +
                "        <fengli><![CDATA[4-5级]]></fengli>\n" +
                "      </night>\n" +
                "    </weather>\n" +
                "    <weather>\n" +
                "      <date>18日星期一</date>\n" +
                "      <high>高温 12℃</high>\n" +
                "      <low>低温 5℃</low>\n" +
                "      <day>\n" +
                "        <type>小雨</type>\n" +
                "        <fengxiang>无持续风向</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </day>\n" +
                "      <night>\n" +
                "        <type>小到中雨</type>\n" +
                "        <fengxiang>无持续风向</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </night>\n" +
                "    </weather>\n" +
                "    <weather>\n" +
                "      <date>19日星期二</date>\n" +
                "      <high>高温 13℃</high>\n" +
                "      <low>低温 6℃</low>\n" +
                "      <day>\n" +
                "        <type>多云</type>\n" +
                "        <fengxiang>无持续风向</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </day>\n" +
                "      <night>\n" +
                "        <type>小到中雨</type>\n" +
                "        <fengxiang>无持续风向</fengxiang>\n" +
                "        <fengli><![CDATA[<3级]]></fengli>\n" +
                "      </night>\n" +
                "    </weather>\n" +
                "  </forecast>\n" +
                "  <zhishus>\n" +
                "    <zhishu>\n" +
                "      <name>晨练指数</name>\n" +
                "      <value>较不宜</value>\n" +
                "      <detail>有降水，较不宜晨练，室外锻炼请携带雨具。建议年老体弱人群适当减少晨练时间。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>舒适度</name>\n" +
                "      <value>较舒适</value>\n" +
                "      <detail>白天会有降雨，这种天气条件下，人们会感到有些凉意，但大部分人完全可以接受。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>穿衣指数</name>\n" +
                "      <value>冷</value>\n" +
                "      <detail>天气冷，建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>感冒指数</name>\n" +
                "      <value>易发</value>\n" +
                "      <detail>天冷空气湿度大，易发生感冒，请注意适当增加衣服，加强自我防护避免感冒。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>晾晒指数</name>\n" +
                "      <value>不宜</value>\n" +
                "      <detail>有降水，不适宜晾晒。若需要晾晒，请在室内准备出充足的空间。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>旅游指数</name>\n" +
                "      <value>适宜</value>\n" +
                "      <detail>稍凉，但是有较弱降水和微风作伴，会给您的旅行带来意想不到的景��，适宜旅游，可不要错过机会呦！</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>紫外线强度</name>\n" +
                "      <value>最弱</value>\n" +
                "      <detail>属弱紫外线辐射天气，无需特别防护。若长期在户外，建议涂擦SPF在8-12之间的防晒护肤品。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>洗车指数</name>\n" +
                "      <value>不宜</value>\n" +
                "      <detail>不宜洗车，未来24小时内有雨，如果在此期间洗车，雨水和路上的泥水可能会再次弄脏您的爱车。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>运动指数</name>\n" +
                "      <value>较不宜</value>\n" +
                "      <detail>有降水，推荐您在室内进行低强度运动；若坚持户外运动，须注意保暖，做好准备活动，携带雨具。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>约会指数</name>\n" +
                "      <value>较不适宜</value>\n" +
                "      <detail>室外有风，而且有降水，会给室外约会带来一些不便，如果外出约会，请一定做好准备。</detail>\n" +
                "    </zhishu>\n" +
                "    <zhishu>\n" +
                "      <name>雨伞指数</name>\n" +
                "      <value>带伞</value>\n" +
                "      <detail>有降水，请带上雨伞，如果你喜欢雨中漫步，享受大自然给予的温馨和快乐，在短时间外出可收起雨伞。</detail>\n" +
                "    </zhishu>\n" +
                "  </zhishus>\n" +
                "</resp>\n";
                // 输出
        System.out.println(str);
        System.out.println("---将对象转换成string类型的xml End---");
        System.out.println();
        System.out.println("---将String类型的xml转换成对象 Start---");
//        User userTest = (User) XMLUtil.convertXmlStrToObject(User.class, str);
        Weather userTest = (Weather) XMLUtil.convertXmlStrToObject(Weather.class, str);
        System.out.println(userTest);
        System.out.println(userTest.getZhishus().getZhishu().get(0));
        System.out.println("---将String类型的xml转换成对象 End---");
    }
}